import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import HomeView from '../components/HomeView.vue'
import PropertyManagementView from '../components/PropertyManagementView.vue'
import RepairManagementView from '../components/RepairManagementView.vue'
import FeeManagementView from '../components/FeeManagementView.vue'
import UserManagementView from '../components/UserManagementView.vue'
import LoginView from '../components/LoginView.vue'
import AppLayout from '@/components/AppLayout.vue'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'layout',
    component: AppLayout,
    children: [
      {
        path: '',
        name: 'home',
        component: HomeView,
      },
    {
      path: '/property',
      name: 'property',
      component: PropertyManagementView,
    },
    {
      path: '/repair',
      name: 'repair',
      component: RepairManagementView,
    },
    {
      path: '/fee',
      name: 'fee',
      component: FeeManagementView,
    },
    {
      path: '/user',
      name: 'user',
      component: UserManagementView,
    }
  ]
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView,
  },
  // 重定向其他未匹配的路由到登录页
  {
    path: '/:pathMatch(.*)*',
    redirect: '/login'
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 移除导航守卫，由App.vue组件控制登录流程

export default router